package fr.labri.macchiato.core.model.utils;

/**
 * A time slot has a start day and hour, and an end day and hour
 * 
 * @author Matthieu FOUCAULT
 * 
 */
public class TimeSlot {

	private Day startDay, endDay;
	private TimeOfDay startHour, endHour;

	TimeSlot() {
	}

	/**
	 * @param startDay
	 * @param endDay
	 * @param startHour
	 * @param endHour
	 */
	public TimeSlot(Day startDay, Day endDay, TimeOfDay startHour,
			TimeOfDay endHour) {
		this.startDay = startDay;
		this.endDay = endDay;
		this.startHour = startHour;
		this.endHour = endHour;
		
	}

	/**
	 * @return the startDay
	 */
	public Day getStartDay() {
		return startDay;
	}

	/**
	 * @param startDay
	 *            the startDay to set
	 */
	public void setStartDay(Day startDay) {
		this.startDay = startDay;
	}

	/**
	 * @return the endDay
	 */
	public Day getEndDay() {
		return endDay;
	}

	/**
	 * @param endDay
	 *            the endDay to set
	 */
	public void setEndDay(Day endDay) {
		this.endDay = endDay;
	}

	/**
	 * @return the startHour
	 */
	public TimeOfDay getStartHour() {
		return startHour;
	}

	/**
	 * @param startHour
	 *            the startHour to set
	 */
	public void setStartHour(TimeOfDay startHour) {
		this.startHour = startHour;
	}

	/**
	 * @return the endHour
	 */
	public TimeOfDay getEndHour() {
		return endHour;
	}

	/**
	 * @param endHour
	 *            the endHour to set
	 */
	public void setEndHour(TimeOfDay endHour) {
		this.endHour = endHour;
	}

	/**
	 * 
	 * @param timeSlot
	 * @return true if the {@link TimeSlot} overlaps with the current one, false
	 *         otherwise
	 */
	public boolean overlaps(TimeSlot timeSlot) {
		if (timeSlot.getEndDay().getValue() < getStartDay().getValue()
				|| timeSlot.getStartDay().getValue() > getEndDay().getValue())
			// The two time slots have no days in common
			return false;

		if (timeSlot.getEndHour().compareTo(getStartHour()) < 0
				|| timeSlot.getStartHour().compareTo(getEndHour()) > 0)
			return false;

		return true;
	}

}
